package com.credithc.signature.manager.controller.management;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.baseserv.pageHelper.PageInfo;
import com.credithc.signature.manager.ro.CompanyRo;
import com.credithc.signature.manager.ro.ProductRo;
import com.credithc.signature.manager.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhq
 * 接收租户信息
 *
 */
@RestController
@RequestMapping("/manager/scs/v2/")
public class CompanyController {

    @Autowired
    private MessageFactory messageFactory;

    @Autowired
    private CompanyService companyService;

//    @PostMapping("/company/redis")
//    public Message companyToRedis (@RequestBody List<CompanyRo> companys){
//        if (companys != null) {
//            companyService.companyToRedis(companys);
//        }
//        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
//    }

    @GetMapping("/company")
    public Message companyList(){
        PageInfo<CompanyRo> list = companyService.getCompanyList();
        Map<String, Object> pageInfo = new HashMap<>(16);
        pageInfo.put("pageInfo", list);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, pageInfo);
    }

    @GetMapping("/product")
    public Message productList(Integer companyName){
        PageInfo<ProductRo> list = companyService.getProductList(companyName);
        Map<String, Object> pageInfo = new HashMap<>(16);
        pageInfo.put("pageInfo", list);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, pageInfo);
    }

    @GetMapping("/product/user")
    public Message userList(){
        PageInfo<ProductRo> list = companyService.getUserList();
        Map<String, Object> pageInfo = new HashMap<>(16);
        pageInfo.put("pageInfo", list);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, pageInfo);
    }

}
